<?php 
session_start();
ob_start();
?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php include ("ewconfig.php") ?>
<?php include ("db.php") ?>
<?php include ("articleinfo.php") ?>
<?php include ("advsecu.php") ?>
<?php include ("phpmkrfn.php") ?>
<?php include ("ewupload.php") ?>
<?php

// Initialize common variables
$x_id = NULL;
$ox_id = NULL;
$z_id = NULL;
$ar_x_id = NULL;
$ari_x_id = NULL;
$x_idList = NULL;
$x_idChk = NULL;
$cbo_x_id_js = NULL;
$x_status = NULL;
$ox_status = NULL;
$z_status = NULL;
$ar_x_status = NULL;
$ari_x_status = NULL;
$x_statusList = NULL;
$x_statusChk = NULL;
$cbo_x_status_js = NULL;
$x_image = NULL;
$ox_image = NULL;
$z_image = NULL;
$fs_x_image = 0;
$fn_x_image = "";
$ct_x_image = "";
$wd_x_image = 0;
$ht_x_image = 0;
$a_x_image = "";
$ar_x_image = NULL;
$ari_x_image = NULL;
$x_imageList = NULL;
$x_imageChk = NULL;
$cbo_x_image_js = NULL;
$fs_x_image = 0;
$fn_x_image = "";
$ct_x_image = "";
$wd_x_image = 0;
$ht_x_image = 0;
$a_x_image = "";
$x_title = NULL;
$ox_title = NULL;
$z_title = NULL;
$ar_x_title = NULL;
$ari_x_title = NULL;
$x_titleList = NULL;
$x_titleChk = NULL;
$cbo_x_title_js = NULL;
/*$x_category_id = NULL;
$ox_category_id = NULL;
$z_category_id = NULL;
$ar_x_category_id = NULL;
$ari_x_category_id = NULL;
$x_category_idList = NULL;
$x_category_idChk = NULL;
$cbo_x_category_id_js = NULL;*/
$x_description = NULL;
$ox_description = NULL;
$z_description = NULL;
$ar_x_description = NULL;
$ari_x_description = NULL;
$x_descriptionList = NULL;
$x_descriptionChk = NULL;
$cbo_x_description_js = NULL;
$x_content = NULL;
$ox_content = NULL;
$z_content = NULL;
$ar_x_content = NULL;
$ari_x_content = NULL;
$x_contentList = NULL;
$x_contentChk = NULL;
$cbo_x_content_js = NULL;
$x_sort = NULL;
$ox_sort = NULL;
$z_sort = NULL;
$ar_x_sort = NULL;
$ari_x_sort = NULL;
$x_sortList = NULL;
$x_sortChk = NULL;
$cbo_x_sort_js = NULL;
$x_author_id = NULL;
$ox_author_id = NULL;
$z_author_id = NULL;
$ar_x_author_id = NULL;
$ari_x_author_id = NULL;
$x_author_idList = NULL;
$x_author_idChk = NULL;
$cbo_x_author_id_js = NULL;
$x_modified_id = NULL;
$ox_modified_id = NULL;
$z_modified_id = NULL;
$ar_x_modified_id = NULL;
$ari_x_modified_id = NULL;
$x_modified_idList = NULL;
$x_modified_idChk = NULL;
$cbo_x_modified_id_js = NULL;
$x_created_date = NULL;
$ox_created_date = NULL;
$z_created_date = NULL;
$ar_x_created_date = NULL;
$ari_x_created_date = NULL;
$x_created_dateList = NULL;
$x_created_dateChk = NULL;
$cbo_x_created_date_js = NULL;
$x_updated_date = NULL;
$ox_updated_date = NULL;
$z_updated_date = NULL;
$ar_x_updated_date = NULL;
$ari_x_updated_date = NULL;
$x_updated_dateList = NULL;
$x_updated_dateChk = NULL;
$cbo_x_updated_date_js = NULL;
?>
<?php

// Get key
$x_id = @$_GET["id"];
if (($x_id == "") || (is_null($x_id))) {
	ob_end_clean();
		switch($_SESSION["session_cms_mode"]){
			case "edit":
				header("Location: articleview.php?id=". $_SESSION["session_cms_id"] . "&mode=" . $_SESSION["session_cms_mode"]);
			break;
			default:
				header("Location: articlelist.php");
			break;
		}	
	exit();
}
if (!is_numeric($x_id)) {
	ob_end_clean();
		switch($_SESSION["session_cms_mode"]){
			case "edit":
				header("Location: articleview.php?id=". $_SESSION["session_cms_id"] . "&mode=" . $_SESSION["session_cms_mode"]);
			break;
			default:
				header("Location: articlelist.php");
			break;
		}	
	exit();
}

// Get action
$sAction = @$_POST["a_view"];
if (($sAction == "") || ((is_null($sAction)))) {
	$sAction = "I";	// Display record
}

// Open connection to the database
$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);
switch ($sAction)
{
	case "I": // Display record
		if (!LoadData($conn)) { // Load record
			$_SESSION[ewSessionMessage] = "No records found";
			phpmkr_db_close($conn);
			ob_end_clean();
				switch($_SESSION["session_cms_mode"]){
					case "edit":
						header("Location: articleview.php?id=". $_SESSION["session_cms_id"] . "&mode=" . $_SESSION["session_cms_mode"]);
					break;
					default:
						header("Location: articlelist.php");
					break;
				}	
			exit();
		}
}
?>
<?php include ("header.php") ?>
<script type="text/javascript">
<!--
EW_LookupFn = "ewlookup.php"; // ewlookup file name
EW_AddOptFn = "ewaddopt.php"; // ewaddopt.php file name

//-->
</script>
<script type="text/javascript" src="ewp.js"></script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="admin_td_title">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td class="admin_title"><?=str_replace(","," &gt; ",$_SESSION['session_cms_title'])?> &raquo; View&nbsp;</td>
		   </tr>
		 </table>
 	</td>
  </tr>
</table>
<br>
<?php switch($_SESSION["session_cms_mode"]){ case "edit":?>
		<a href="<?php if ($x_id <> "") {echo "articleedit.php?id=" . urlencode($x_id) . "&mode=edit"; } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>" class="button-modify">Edit</a>&nbsp;
<?php break; ?>
<?php default: ?>
<a href="articlelist.php" class="button-modify">Back to List</a>&nbsp;
<a href="<?php if ($x_id <> "") {echo "articleedit.php?id=" . urlencode($x_id); } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>" class="button-modify">Edit</a>&nbsp;
<a href="<?php if ($x_id <> "") {echo "articledelete.php?id=" . urlencode($x_id); } else { echo "javascript:alert('Invalid Record! Key is null');";} ?>" class="button-modify">Delete</a>&nbsp;
<?php break; } ?>
<br />
<form>
<br />
<?php
if (@$_SESSION[ewSessionMessage] <> "") {
?>
	<p><span class="ewmsg"><?php echo $_SESSION[ewSessionMessage]; ?></span></p>
<?php
	$_SESSION[ewSessionMessage] = ""; // Clear message
}
?>
<table class="ewTable">
	<tr>
		<td class="ewTableHeader"><span>status</span></td>
		<td class="ewTableAltRow"><span>
<?php
switch ($x_status) {
	case "A":
		$sTmp = "Tampil";
		break;
	case "I":
		$sTmp = "Tidak Tampil";
		break;
	default:
		$sTmp = "";
}
$ox_status = $x_status; // Backup original value
$x_status = $sTmp;
?>
<?php echo get_icon_status($ox_status); ?>
<?php $x_status = $ox_status; // Restore original value ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Gambar</span></td>
		<td class="ewTableAltRow"><span>
<?php if ((!is_null($x_image)) &&  $x_image <> "") { ?>
<img src="<?php echo ewUploadPathEx(False, "../uploads/article/thumbs/") . $x_image ?>" border=0 width="150">
<?php } ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Judul</span></td>
		<td class="ewTableAltRow"><span>
<?php echo $x_title; ?>
</span></td>
	</tr>
	<!--tr>
		<td class="ewTableHeader"><span>Kategori</span></td>
		<td class="ewTableAltRow"><span>
<?php
/*if ((!is_null($x_category_id)) && ($x_category_id <> "")) {
	$sSqlWrk = "SELECT `title` FROM `category`";
	$sTmp = $x_category_id;
	$sTmp = addslashes($sTmp);
	$sSqlWrk .= " WHERE `id` = " . $sTmp . "";
	$sSqlWrk .= " ORDER BY `title` Asc";
	$rswrk = phpmkr_query($sSqlWrk,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL:' . $sSqlWrk);
	if ($rswrk && $rowwrk = phpmkr_fetch_array($rswrk)) {
		$sTmp = $rowwrk["title"];
	}
	@phpmkr_free_result($rswrk);
} else {
	$sTmp = "";
}
$ox_category_id = $x_category_id; // Backup original value
$x_category_id = $sTmp;*/
?>
<?php //echo $x_category_id; ?>
<?php //$x_category_id = $ox_category_id; // Restore original value ?>
</span></td>
	</tr-->
	<tr>
		<td class="ewTableHeader"><span>Deskripsi</span></td>
		<td class="ewTableAltRow"><span>
<?php echo $x_description; ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Isi</span></td>
		<td class="ewTableAltRow"><span>
<?php echo $x_content; ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Pembuat</span></td>
		<td class="ewTableAltRow"><span>
<?php echo get_name_of_user($x_author_id); ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Modifikasi oleh</span></td>
		<td class="ewTableAltRow"><span>
<?php echo get_name_of_user($x_modified_id); ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Tanggal dibuat</span></td>
		<td class="ewTableAltRow"><span>
<?php echo FormatDateTime($x_created_date,7); ?>
</span></td>
	</tr>
	<tr>
		<td class="ewTableHeader"><span>Tanggal dirubah</span></td>
		<td class="ewTableAltRow"><span>
<?php echo FormatDateTime($x_updated_date,7); ?>
</span></td>
	</tr>
</table>
</form>
<p>
<?php include ("footer.php") ?>
<?php
phpmkr_db_close($conn);
?>
<?php

//-------------------------------------------------------------------------------
// Function LoadData
// - Variables setup: field variables

function LoadData($conn)
{
	global $x_id;
	$sFilter = ewSqlKeyWhere;
	if (!is_numeric($x_id)) return false;
	$x_id =  (get_magic_quotes_gpc()) ? stripslashes($x_id) : $x_id;
	$sFilter = str_replace("@id", AdjustSql($x_id), $sFilter); // Replace key value
	$sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, $sFilter, "");
	$rs = phpmkr_query($sSql,$conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql);
	if (phpmkr_num_rows($rs) == 0) {
		$bLoadData = false;
	} else {
		$bLoadData = true;
		$row = phpmkr_fetch_array($rs);

		// Get the field contents
		$GLOBALS["x_id"] = $row["id"];
		$GLOBALS["x_status"] = $row["status"];
		$GLOBALS["x_image"] = $row["image"];
		$GLOBALS["x_title"] = $row["title"];
		//$GLOBALS["x_category_id"] = $row["category_id"];
		$GLOBALS["x_description"] = $row["description"];
		$GLOBALS["x_content"] = $row["content"];
		$GLOBALS["x_sort"] = $row["sort"];
		$GLOBALS["x_author_id"] = $row["author_id"];
		$GLOBALS["x_modified_id"] = $row["modified_id"];
		$GLOBALS["x_created_date"] = $row["created_date"];
		$GLOBALS["x_updated_date"] = $row["updated_date"];
	}
	phpmkr_free_result($rs);
	return $bLoadData;
}
?>
